<template>
<!-- 这是图片详情页 -->
    <div class="photoinfo-container">
        <h3 class="title">{{ photoinfo.title }}</h3>
        <div class="subtitle">
            <span>发表时间：{{ photoinfo.add_time | dateFormat}}</span>
            <span>点击：{{ photoinfo.click}}次</span>
        </div>
        <hr>
        <!-- 缩略区域 -->
        <vue-preview :slides="list" @close="handleClose"></vue-preview>
        <!-- 图片内容区域 -->
        <div class="content" v-html="photoinfo.zhaiyao"></div>
        <!-- 评论区域 -->
        <cmt-box :id='this.id'></cmt-box>
    </div>
</template>
<script>
import {Toast} from 'mint-ui';
import comments from '../subComponents/Comment.vue';
export default {
    data(){
        return {
            id:this.$route.params.id,//从路由中获取图片id
            photoinfo:{},//图片详情内容
            list:[]//所有图片集合
        }
    },
    created(){
        this.getPhotoInfo();
        this.getThumbs();
    },
    methods:{
        getPhotoInfo(){//获取图片详情
            this.$http.get('getimageinfo/'+this.id).then(result=>{
                console.log(result.body);
                if(result.body.status == 0){
                    this.photoinfo = result.body.data[0];
                }else{
                    Toast('获取详情数据失败');
                }
            })
        },
        getThumbs(){//获取图片的缩略图
            this.$http.get('getthumbimages/'+this.id).then(result=>{
                console.log(result.body);
                if(result.body.status == 0){
                    result.body.data.forEach(item => {
                        item.msrc = item.src;
                        item.w = 600;
                        item.h = 400;
                    });
                    this.list = result.body.data;
                }else{
                    Toast("获取缩略图失败");
                }
            })
        },
        handleClose () {
            console.log('close event')
        }
    },
    components:{
        "cmt-box":comments
    }
}
</script>
<style lang="scss">
.photoinfo-container{
    padding: 3px;
    .title{
        color:#26a2ff;
        text-align: center;
        font-size: 15px;
        margin: 15px 0;
    }
    .subtitle{
        display: flex;
        justify-content: space-between;
        font-size: 14px;
        margin:0 5px;
    }
    .content{
        font-size: 13px;
        line-height: 30px;
    }
    .my-gallery{
        // display: flex;
        figure {
            margin: 1em 20px;
        } 
        img{
           width: 100%;
       }
    }
}
</style>

